package com.newasia.user.services;

import com.newasia.user.IAreaService;
import com.newasia.user.constants.SysRetCodeConstants;
import com.newasia.user.converter.AreaConverter;
import com.newasia.user.dal.entitys.Areas;
import com.newasia.user.dal.persistence.AreasMapper;
import com.newasia.user.dto.AreaListRequest;
import com.newasia.user.dto.AreaListResponse;
import com.newasia.user.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@Service
public class AreaServiceImpl implements IAreaService {

    @Autowired
    AreasMapper areasMapper;

    @Autowired
    AreaConverter areaConverter;

    @Override
    public AreaListResponse areaList(AreaListRequest request) {

        AreaListResponse response = new AreaListResponse();
        try{
            request.requestCheck();
            List<Areas> areaList = areasMapper.selectByparentId(request.getParentId());
            response.setAreasDtos(areaConverter.address2List(areaList));
            response.setCode(SysRetCodeConstants.SUCCESS.getCode());
            response.setMsg(SysRetCodeConstants.SUCCESS.getMessage());
        }catch (Exception e){
            log.info("areaList error:");
            ExceptionProcessorUtils.wrapperHandlerException(response,e);
        }
        return response;
    }
}
